using System.Diagnostics;

using Microsoft.AspNetCore.Mvc;

using ZZ_ICU.Models;

namespace ZZ_ICU.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        // 受保护的首页：未登录用户会被重定向到 /Login
        public IActionResult Index()
        {
            // 检查用户是否已登录
            var userId = HttpContext.Session.GetString("UserId");
            if (string.IsNullOrEmpty(userId))
            {
                return RedirectToAction("Index", "Login");
            }

            // 将基础用户信息传入 View 进行展示
            ViewBag.UserName = HttpContext.Session.GetString("UserName");
            ViewBag.UserType = HttpContext.Session.GetString("UserType");
            return View();
        }


        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
